<?php

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Auth;

class User extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'mobile', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password',
    ];

    protected $casts = [
        'is_admin' => 'boolean',
        'is_show' => 'boolean'
    ];

    const IS_SHOW = true;
    const NOT_SHOW = false;

    public static $showMap = [
        self::IS_SHOW => '是',
        self::NOT_SHOW => '否'
    ];

    const IS_ADMIN = true;
    const NOT_ADMIN = false;

    public static $adminMap = [
        self::IS_ADMIN => '是',
        self::NOT_ADMIN => '否'
    ];

    // 当前用户参与竞价的商品
    public function biddingProduct()
    {
        return $this->belongsToMany(Product::class, 'product_bids')
            ->orderBy('created_at', 'desc')
            ->withPivot(['money', 'now_price'])
            ->withTimestamps();
    }
}
